package com.wenjie.gateway.exception;


import com.wenjie.common.unifiedReturn.Result;
import com.wenjie.gateway.ResConstant;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * @author wenjie
 * @Description 通用的异常处理器
 * @date 2024/6/11 9:52
 */
@Slf4j
@RestControllerAdvice
public class CommonExceptionHandler {


    /**
     * @Description 登录异常处理
     * @author wenjie
     * @date 2024/6/11 9:57
     */
    @ExceptionHandler(LoginException.class)
    public Result loginException(LoginException ex) {
        ex.printStackTrace();
        return Result.fail(ex.getMessage());
    }


    /**
     * @Description 登录异常处理
     * @author wenjie
     * @date 2024/6/11 9:57
     */
    @ExceptionHandler(NoLoginException.class)
    public Result noLoginException(LoginException ex) {
        ex.printStackTrace();
        return Result.create(ResConstant.NO_LOGIN, ex.getMessage());
    }

    /**
     * @Description 权限校验异常处理
     * @author wenjie
     * @date 2024/6/11 9:57
     */

    @ExceptionHandler(AuthorityException.class)
    public Result authorityException(AuthorityException ex) {
        ex.printStackTrace();
        return Result.fail(ex.getMessage());
    }


}
